package com.fenfen.novel.utils;

import com.fenfen.novel.db.NovelReadRecord;
import com.fenfen.novel.model.Chapter;
import com.fenfen.novel.model.Novel;

import java.util.Date;

public class NovelRecordUtil {

  public static NovelReadRecord convertToRecordWithAll(Novel novel, int chapterOrder, int chapterId) {
    NovelReadRecord record = new NovelReadRecord();
    record.setNovelId(novel.getId());
    record.setNovelName(novel.getName());
    record.setNovelCover(novel.getNovelCover());
    record.setChapterCount(novel.getChapterCount());
    record.setChapterId(chapterId);
    record.setChapterOrder(chapterOrder);
    record.setCreate_time(new Date());
    record.setUpdate_time(new Date());
    return record;
  }

  public static NovelReadRecord convertToRecordWithAll(Chapter chapter, Novel novel) {
    return convertToRecordWithAll(novel, chapter.getChapterOrder(), chapter.getId());
  }

  public static NovelReadRecord convertToRecordWithChapter(int novelId, Chapter chapter) {
    return convertToRecordWithChapter(novelId, chapter.getChapterOrder(), chapter.getId());
  }

  public static NovelReadRecord convertToRecordWithChapter(int novelId, int chpaterOrder, int chapterId) {
    NovelReadRecord record = new NovelReadRecord();
    record.setNovelId(novelId);
    record.setChapterId(chapterId);
    record.setChapterOrder(chpaterOrder);
    record.setCreate_time(new Date());
    record.setUpdate_time(new Date());
    return record;
  }

  public static Chapter convertToChapter(NovelReadRecord record) {
    Chapter chapter = new Chapter();
    chapter.setId(record.getChapterId());
    chapter.setChapterOrder(record.getChapterOrder());
    chapter.setNovelId(record.getNovelId());
    return chapter;
  }

  //更新novel_read_record中novel部分
  public static NovelReadRecord updateNovelRecordWithNovel(NovelReadRecord record, Novel novel) {
    record.setNovelName(novel.getName());
    record.setNovelCover(novel.getNovelCover());
    record.setChapterCount(novel.getChapterCount());
    record.setUpdate_time(new Date());
    return record;
  }

  //更新novel_read_record中chapter部分
  public static NovelReadRecord updateNovelRecordWithChapter(NovelReadRecord record, Chapter chapter) {
    record.setChapterId(chapter.getId());
    record.setChapterOrder(chapter.getChapterOrder());
    record.setUpdate_time(new Date());
    return record;
  }

  public static NovelReadRecord convertToRecordWithNovel(Novel novel) {
    NovelReadRecord record = new NovelReadRecord();
    record.setNovelId(novel.getId());
    record.setNovelCover(novel.getNovelCover());
    record.setNovelName(novel.getName());
    record.setChapterCount(novel.getChapterCount());
    record.setCreate_time(new Date());
    record.setUpdate_time(new Date());
    return record;
  }
}
